let App = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // 快捷导航
    nav_select: false,
    // 当前页面参数
    options: {},
    exist_address: false, // 是否存在收货地址
    showImages: [],
    is_showImages:false,
    // 禁用submit按钮
    disabled: false,
    hasError: false,
    error: '',
    user_id:'',
    sex:'',
    page_sex:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    
    // 当前页面参数
    this.data.options = options;
    this.setData({
     // user_id: options.user_id,
      address_id: options.address_id
    })
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    // 获取当前订单信息
    //this.getOrderData();
    //获取当前用户信息
    //this.getUserDetail();
    //获取相亲信息
    this.getDateDetail();
  },

  /**
   * 获取相亲信息
   */
  getDateDetail:function(){
    let _this = this;
    //let user_id = _this.data.user_id;
    let address_id = _this.data.address_id;
    App._get('address/detail', { address_id: address_id, type:'detail'}, function (result) {
      console.log(result);
      let showImagesArr = [];
      if (result.data.detail.images){
        for (var j = 0; j < result.data.detail.images.length;j++){
          showImagesArr.push(App.root  + result.data.detail.images[j]);
        }
      }
      _this.setData(result.data);
      _this.setData({
        showImages: showImagesArr
      })
      _this.setData({
        sex: result.data.detail.sex
      })
      
    });
  },
  /**
   * 获取当前用户信息
   */
  getUserDetail: function () {
    let _this = this;
    let user_id = _this.data.user_id;
    App._get('user.index/detail', {user_id:user_id}, function (result) {
      //console.log(result.data);
      _this.setData(result.data);
    });
  },


  //放大图片查看
  previewImage: function (e) {
    let key = e.target.dataset.id;
    let imgSrc = this.data.showImages;

    wx.previewImage({
      current: imgSrc[key],
      urls: imgSrc
    })
  },

  //展示或关闭 图片
  is_showImages:function(){
    let that = this;
    if (that.data.is_showImages){
      that.setData({
        is_showImages: false
      });
    }else{
      that.setData({
        is_showImages: true
      });
    }
    console.log(that.data.is_showImages);
  },

  //关注
  guanzhu: function (e) {
    let to_user_id = e.currentTarget.dataset.user_id
    //console.log(user_id);
    App._get('user.follow/follow', {
      to_user_id: to_user_id
    }, function (result) {
      //console.log(result);
      App.showSuccess(result.msg);
    });
  },

});